import { GameError } from './GameError';

/**
 * RPG相关错误类
 */

/**
 * 等级不足错误
 */
export class InsufficientLevelError extends GameError {
    readonly code = 'INSUFFICIENT_LEVEL';
    readonly statusCode = 403;

    constructor(requiredLevel: number, currentLevel: number, action: string) {
        super(`等级不足，${action}需要等级${requiredLevel}，当前等级${currentLevel}`, {
            requiredLevel,
            currentLevel,
            action
        });
    }
}

/**
 * 经验值无效错误
 */
export class InvalidExpError extends GameError {
    readonly code = 'INVALID_EXP';
    readonly statusCode = 400;

    constructor(exp: number) {
        super(`无效的经验值：${exp}`, { exp });
    }
}

/**
 * 属性点不足错误
 */
export class InsufficientAttributePointsError extends GameError {
    readonly code = 'INSUFFICIENT_ATTRIBUTE_POINTS';
    readonly statusCode = 400;

    constructor(required: number, available: number) {
        super(`属性点不足，需要：${required}，可用：${available}`, {
            required,
            available
        });
    }
}

/**
 * 技能学习错误
 */
export class SkillLearnError extends GameError {
    readonly code = 'SKILL_LEARN_ERROR';
    readonly statusCode = 400;

    constructor(skillName: string, reason: string) {
        super(`技能 ${skillName} 学习失败：${reason}`, {
            skillName,
            reason
        });
    }
}

/**
 * 技能使用错误
 */
export class SkillUsageError extends GameError {
    readonly code = 'SKILL_USAGE_ERROR';
    readonly statusCode = 400;

    constructor(skillName: string, reason: string) {
        super(`技能 ${skillName} 使用失败：${reason}`, {
            skillName,
            reason
        });
    }
}

/**
 * 战斗状态错误
 */
export class BattleStateError extends GameError {
    readonly code = 'BATTLE_STATE_ERROR';
    readonly statusCode = 409;

    constructor(currentState: string, requiredState: string) {
        super(`战斗状态错误，当前状态：${currentState}，需要状态：${requiredState}`, {
            currentState,
            requiredState
        });
    }
}

/**
 * 血统错误
 */
export class BloodlineError extends GameError {
    readonly code = 'BLOODLINE_ERROR';
    readonly statusCode = 400;

    constructor(bloodlineName: string, reason: string) {
        super(`血统 ${bloodlineName} 错误：${reason}`, {
            bloodlineName,
            reason
        });
    }
}

/**
 * 装备错误
 */
export class EquipmentError extends GameError {
    readonly code = 'EQUIPMENT_ERROR';
    readonly statusCode = 400;

    constructor(equipName: string, reason: string) {
        super(`装备 ${equipName} 错误：${reason}`, {
            equipName,
            reason
        });
    }
}

/**
 * 技能未找到错误
 */
export class SkillNotFoundError extends GameError {
    readonly code = 'SKILL_NOT_FOUND';
    readonly statusCode = 404;

    constructor(skillId: string) {
        super(`技能未找到：${skillId}`, { skillId });
    }
}

/**
 * 通用RPG错误
 */
export class RPGError extends GameError {
    readonly code = 'RPG_ERROR';
    readonly statusCode = 500;

    constructor(message: string, data?: any) {
        super(message, data);
    }
}